#include "comm.hpp"

int main()
{
    key_t k = getKey();
    int shmid = getShm(k);

    char* start = (char*)attachShm(shmid);
    printf("client: attach success, address start: %p\n", start);

    const char *msg = "我是客户端，正在和你发消息！";
    int cnt = 0;
    pid_t pid = getpid();
    while (true)
    {
        sleep(1);
        //发送5条消息
        if (cnt == 5)
        {
            snprintf(start, MAX_SIZE, "break");
            break;
        }
        snprintf(start, MAX_SIZE, "%s[pid:%d][消息编号:%d]", msg, pid, ++cnt);

    }

    detachShm(start);
    printf("client: detachShm success!!!\n");

    return 0;
}